package com.ibm.sample.library.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ibm.sample.library.dao.impl.BookDao;
import com.ibm.sample.library.dao.impl.CategoryDao;
import com.ibm.sample.library.model.Book;
import com.ibm.sample.library.model.Category;
import com.ibm.sample.library.service.IService;

@Repository
@Transactional
public class Service implements IService
{
    @Autowired
    private BookDao bookDao;

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public Category getCategoryByName(String name)
    {
        return categoryDao.getByName(name);
    }

    @Override
    public void saveCategory(Category category)
    {
        categoryDao.save(category);
    }

    @Override
    public void updateCategory(Category category)
    {
        categoryDao.update(category);
    }

    @Override
    public void deleteCategoryById(long id)
    {
        categoryDao.deleteById(id);
    }

    @Override
    public List<Category> findAllCategory()
    {
        return categoryDao.findAll();
    }

    @Override
    public List<Book> findAllBook()
    {
        return bookDao.findAll();
    }
}
